home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stikspec / doc / stikspec.txt
Encoding:
Text File  |  1995-10-02  |  15.1 KB  |  364 lines

  1. Description of TRANSPRT.H functions.
  2.  
  3. See transprt.h and drivers.h for associated definitions etc..
  4.  
  5.  
  6. char  * cdecl KRmalloc(int32);
  7.  
  8.   - Allocate a block of memory from STiK's internal buffer.
  9.   - Returns (char *)NULL if sufficient memory is not available.
  10.   - These memory functions are basically the code in K&R 1 pp 174 - 177
  11.     but there are some minor differences.  morecore is *never* called.
  12.     These functions use one block of memory that is Malloc'd when
  13.     the ACC loads.  Also, the header size is 8 bytes since allocations
  14.     greater than 2^16 are allowed, therefore memory is always
  15.     allocated in multiples of 8 bytes.
  16.   - Some bits in the headers are checked during KRmalloc() and KRfree()
  17.     to determine if memory corruption has occured.
  18.  
  19.  
  20. void    cdecl KRfree(char *);
  21.  
  22.   - Free a block that was allocated by KRmalloc() or KRrealloc().
  23.   - Currently, KRfree() does *not* check for a NULL pointer...
  24.     (but this is such a good idea, that I will add the test)
  25.  
  26.  
  27. int32   cdecl KRgetfree(int16 flag);
  28.  
  29.   - Return the amount of free space left in STiK's internal buffer.
  30.   - If flag is TRUE return the largest block, otherwise return
  31.     total available space.
  32.  
  33.  
  34. char  * cdecl KRrealloc(char *block, int32 newsize);
  35.  
  36.   - Change the size of an allocated block.  If newsize is greater than
  37.     oldsize, then copy the contents into the new block.
  38.   - If (newsize == 0) then free the block and return (char *)NULL.
  39.   - If (block == (char *)NULL) then allocate a new block of newsize
  40.     bytes, but zero the contents before returning.
  41.  
  42.  
  43. char  * cdecl get_err_text(int16 code);
  44.  
  45.   - Returns a pointer to a description of an internal STiK error code.
  46.     The absolute value of code is used to look up a an array of char *.
  47.     If code is out of range, a pointer to "" is returned.
  48.  
  49.  
  50. char  * cdecl getvstr(char *var);
  51.  
  52.   - Returns a pointer to the value of a STiK config variable
  53.     set in DEFAULT.CFG  The lookup is not case sensitive.
  54.     The pointer is to the first non blank char after the '='.
  55.   - If a variable does not exist, a pointer to "0" is returned.
  56.   - If a variable has no `= value' "1" is returned (present == TRUE)
  57.   - If a variable has '=', but no value, then "0" is returned.
  58.  
  59.  
  60. int16   cdecl carrier_detect(void);
  61.  
  62.   - If the config variable CDVALID is FALSE, then 0 (unknown) is returned.
  63.   - Otherwise, returns +1 for carrier, -1 for no carrier.
  64.  
  65.  
  66. int16   cdecl TCP_open(uint32 rhost, int16 rport, int16 tos, uint16 obsize);
  67.  
  68.   - Attempts to open a connection to rhost on rport.
  69.   - tos is Type of Service.  I've never experimented with non zero values.
  70.   - obsize is the size of the output buffer to allocate.
  71.     TCP_send() places data in this buffer.  Size dependant on requirements.
  72.     Bigger is not necessarily better.  500 to 2000 should be OK.
  73.   - TCP_open() returns a connection handle (0..n) or a
  74.     a negative error code.
  75.   - TCP_open() returns immediately, without waiting for the
  76.     connection to establish.
  77.  
  78.   - Passive opens:-
  79.   - If rhost is 0, then the connection becomes a LISTEN socket, and
  80.     waits for a connection request from a remote host.
  81.   - In this case, rport is the assignment of the local port
  82.     and *not* the remote port...
  83.   - There is no provision for limiting the socket to listen for
  84.     connection from a particular host or port. (ie: always INADDR_ANY)
  85.   - The port must be continually polled for input.  There is
  86.     no other way to see if a connection has been made.
  87.   - Sending data to a connection in LISTEN mode is an error.
  88.   - If a remote host makes a connection, the connection will
  89.     no longer be in LISTEN mode.  Requests from other hosts
  90.     will be denied.  To circumvent this, do another TCP_open(0,...)
  91.     when the first connection is activated.  (or have several
  92.     connections passive opened at the same time)
  93.  
  94.   - NOTE To test the current status of the socket, simply
  95.     call CNbyte_count().  If E_LISTEN is returned, then
  96.     the socket is still in TLISTEN state.  Any other function
  97.     that has a connection handle as an argument will return
  98.     the same error, except TCP_close().
  99.  
  100.   - Author's apology...  It's very rough, but it's really only
  101.     for my own testing.  If I don't have time to make something
  102.     better soon, this method should at least be usable.  The reason
  103.     that it is so rough is that I never intended having LISTEN
  104.     sockets.  Hence, this is a hack.
  105.  
  106.  
  107. int16   cdecl TCP_close(int16 cn, int16 timeout);
  108.  
  109.   - Closes a connection.  cn is the connection handle.
  110.   - Returns 0 or a negative error code.
  111.   - timeout is the time in seconds to wait for the connection to close.
  112.     TCP_close() must negotiate the close with the remote host, so
  113.     it can take some time if the net is slow.  Pending data may need
  114.     to be received and discarded before the connection closes cleanly.
  115.   - Note that TCP_close() *must* be called in order to free memory
  116.     that has been allocated for the connection.
  117.   - A timeout of 0 is acceptable for immediate close.
  118.   - If the ESC key is pressed during the timeout period, TCP_close()
  119.     returns immediately with a E_USERTIMEOUT error code.
  120.  
  121.  
  122. int16   cdecl TCP_send(int16 cn, char *buf, int16 len);
  123.  
  124.   - Send len bytes from buf on the connection cn.
  125.   - Returns E_NORMAL for success, or an error code.
  126.   - Note that the error E_OBUFFULL is *not* a fatal error.
  127.     If E_OBUFFULL is return, you should loop, for your own timeout period,
  128.     waiting for the output buffer to clear.  If you have defined a buffer
  129.     that is smaller than the block you are sending, it will never clear.
  130.  
  131.  
  132. int16   cdecl TCP_wait_state(int16 cn, int16 state, int16 timeout);
  133.  
  134.   - Wait for timeout seconds for the connection cn, to reach a particular
  135.     TCP state.  The primary use for this function is to wait for the
  136.     TESTABLISH state after calling TCP_open() (though this is not really
  137.     necessary).
  138.   - Returns E_NORMAL or an error code.
  139.   - If the ESC key is pressed while this function is waiting,
  140.     it returns E_USERTIMEOUT.
  141.  
  142.  
  143. int16   cdecl TCP_ack_wait(int16 cn, int16 timeout);
  144.  
  145.   - Wait for all data in the output buffer to be acknowledged by
  146.     the remote host.
  147.   - Note that the timeout is in milliseconds
  148.   - Returns E_NORMAL regardless of whether the timeout is reached
  149.     or the output buffer clears.
  150.   - This is a kludge that you should probably never use...
  151.  
  152.  
  153. int16   cdecl UDP_open(uint32 rhost, int16 rport);
  154.  
  155.   - Open a UDP (datagram) connection with rhost on rport.
  156.   - Returns connection handle or error code.
  157.   - Note that there is really no such thing as a UDP `connection'.
  158.     The UDP functions provide a convenient and consistent method
  159.     for communicating with remote hosts using UDP.
  160.   - UDP is used primarily by the domain name resolver.
  161.  
  162.  
  163. int16   cdecl UDP_close(int16 cn);
  164.  
  165.   - Close the UDP connection cn.
  166.   - Frees the connection handle and any blocks pending in the
  167.     input queue, returns immediately.
  168.  
  169.  
  170. int16   cdecl UDP_send(int16 cn, char *buf, int16 len);
  171.  
  172.   - Sends len bytes from buf on the connection cn.
  173.   - Returns E_NORMAL or an error code.
  174.   - NOTE that the the data will be sent as a single UDP packet, so
  175.     you should make sure that it is appropriately sized for your MTU.
  176.  
  177.  
  178. int16   cdecl CNkick(int16 cn);
  179.  
  180.   - `kick' the connection cn.
  181.   - If there is data waiting to be sent, then restart the retransmission
  182.     sequence as though it is the first transmission.
  183.     If there is no data waiting, send an ACK packet to the remote host
  184.     to let them know we're still here.
  185.   - In theory this is a pointless function.  It is provided so that when
  186.     the user starts bashing the keyboard during a long delay, the
  187.     programmer arrange that something happens as a result.  This should
  188.     save lots of valuable Atari hardware. :-))
  189.   - Since the retransmission algorithm uses exponential backoff,
  190.     (ie: timeout doubles at every retransmission) the function is
  191.     probably not entirely pointless.
  192.   - TCP specs state that excessive retransmissions should be avoided.
  193.   - Returns E_NORMAL or an error code if the connection is invalid.
  194.  
  195.  
  196. int16   cdecl CNbyte_count(int16 cn);
  197.  
  198.   - Return the number of bytes waiting in the input queue for
  199.     connection cn, or an error code.
  200.  
  201.  
  202. int16   cdecl CNget_char(int16 cn);
  203.  
  204.   - Return the next char from the input queue for cn, or
  205.     a negative error code.  A return of E_NODATA is *not* fatal.
  206.   - Note that if you are using CNget_char() for data input then
  207.     your loop *must* include CNbyte_count(), or the housekeep()
  208.     function.
  209.  
  210.  
  211. NDB   * cdecl CNget_NDB(int16 cn);
  212.  
  213.   - Return a pointer to the next block on the input queue for cn, 
  214.     or (NDB *)NULL if there are no packets queued.
  215.   - This is potentially the most efficient way of reading the
  216.     input queue, because the NDB contains a point to the actual
  217.     packet that was read in initially.  No data has been copied
  218.     up to this point.
  219.   - There is no way defined for CNget_NDB() to return any other
  220.     connection error status.
  221.   - The NDB structure is defined in TRANSPRT.H
  222.   - Since CNget_NDB() unlinks the packet from the input queue,
  223.     you must use KRfree() to free the packet and the NDB structure
  224.     as well.  The following code is a guide..
  225.  
  226.         NDB *blk = CNget_NDB(cn);
  227.  
  228.         if (blk != (NDB *)NULL) {
  229.             process_block(blk);
  230.  
  231.             if (blk->ptr)           /* blk->ptr will never be NULL, though */
  232.                 KRfree(blk->ptr);
  233.  
  234.             KRfree(blk);
  235.         }
  236.  
  237.  
  238. int16   cdecl CNget_block(int16 cn, char *blk, int16 len);
  239.  
  240.   - Fills a block starting at blk with len bytes from cn.
  241.   - If the input queue has less than len bytes, then no
  242.     data will be transferred.
  243.   - Returns the number of bytes you requested, or an
  244.     error code.  E_NODATA is *not* a fatal error.
  245.  
  246.  
  247. void    cdecl housekeep(void);
  248.  
  249.   - Performs internal housekeeping duties.
  250.     You don't really need to call this function, but an explanation
  251.     is necessary.  housekeep() is called internally by several
  252.     of the other functions listed here.  In particular, all
  253.     of the CN input functions call housekeep() *except* CNget_char().
  254.     (otherwise a whole packet could be received every time CNget_char()
  255.     is called!)
  256.   - STiK does not do any background or interrupt processing.
  257.     Everything is acheived by polling.  housekeep() is the
  258.     central function of STiK that does this polling.  It calls
  259.     these functions:-
  260.  
  261.     do_resolve();       Resolver processing, including reading packets
  262.     slip_in();          Reading the serial port
  263.     slip_out();         Writing to the serial port
  264.     tcp_timer();        TCP retransmissions
  265.     frag_ttl_check();   Check time to live in fragment reassembly queue
  266.  
  267.   - Currently, STiK.ACC, when enabled, calls evnt_multi with
  268.     MU_TIMER set a timeout of 200 milliseconds.  housekeep()
  269.     is called whenever evnt_multi returns.
  270.  
  271.   - NOTE that the efficiency of STiK relates to this function, but I
  272.     have to admit that housekeep() has not been carefully thought out.
  273.     However, if the functions called by housekeep() have no work
  274.     to do, they return quickly.  All the same, they can each be called
  275.     many times each second.  It would probably be sufficient to call
  276.     them a maximum of perhaps 5 or 10 times per second.
  277.  
  278.  
  279. int16   cdecl resolve(char *dn, char **rdn, uint32 *alist, int16 lsize);
  280.  
  281.   - Resolve a domain name into one or more IP addresses.
  282.     dn is the domain name.
  283.     rdn is the real domain name, which is returned if dn is an alias (CNAME).
  284.     alist is a pointer to an array where the IP address(s) are returned.
  285.     lsize is the size of that array.
  286.   - If the information is in local cache, then resolve will return it
  287.     immediately, otherwise an algorithm for query of nameservers
  288.     is initiated.  This can take some time, however, the resolver has
  289.     an internal limit on the amout of work it will do in attempting
  290.     to resove a hostname.  (Hence the error code `work limit reached')
  291.   - If rdn == (char **)NULL then no value is assigned to it.
  292.     Otherwise, a pointer to the domain name associated with the addresses
  293.     is assigned to *rdn, even if it is the same as that requested.
  294.     This pointer must be freed using KRfree().
  295.   - resolve() returns the number of addresses copied to alist,
  296.     or a negative error code.
  297.   - In retrospect, it might not have been all that smart of me to write
  298.     my own DNS resolver, but it is at least educational :-))
  299.     All the same, it is *not* yet finished.  There are some bugs in
  300.     the code at present, and also inefficiency in my algorithm.
  301.   - I'll work on improving it when (if?) I get the chance.
  302.   - NOTE that STiK.ACC will save the dns cache to domain.txt
  303.     every five minutes if AES is active and STiK is enabled.
  304.  
  305.  
  306. void    cdecl ser_disable(void);
  307.  
  308.   - This function disables the serial port prior to disk I/O
  309.     It should only be necessary for combinations of baud rate/
  310.     cpu speed that do not allow DMA and serial I/O to work together.
  311.     Internally, it calls Jan Kriesten's DEVICE.LIB function
  312.     StopReceiver().  This, in turn, calls an IOCTL function
  313.     that might only work with HSMODEM loaded.  I'm not sure.
  314.   - In the current version of STiK this (and ser_enable)
  315.     return without doing anything.  I'm waiting for bug
  316.     reports before I decide what to do with it.
  317.   - NOTE that if the port is disabled (in later STiK versions)
  318.     it *must* be reenabled immediately after the disk I/O, or
  319.     that is the end of the TCP session :-))
  320.  
  321.  
  322. void    cdecl ser_enable(void);
  323.  
  324.   - See above...
  325.  
  326.  
  327. int16   cdecl set_flag(int16 flag);
  328.  
  329.   - This calls an assembler routine that sets one of 64 possible
  330.     flags using TAS.  The idea is that with proper flag setting
  331.     STiK should function properly in a pre-emptive multitasking
  332.     environment.  They could also be used for locking of other
  333.     well defined processes, such as mailers etc.
  334.   - Currently I'm only using the first two of these flags, for
  335.     housekeep() and do_resolve() which are not re-entrant.
  336.   - I've yet to actually do the work which would ensure proper
  337.     function of STiK in a pre-emptive environment, so if it
  338.     does work, that's accidental.
  339.   - set_flag() returns TRUE if the flag was already set
  340.     (ie: Someone else owns the lock) or FALSE if the flag was clear,
  341.     and set_flag() changed it successfully.  (ie: the lock is ours).
  342.     (in other words, set_flag() returns the value the flag had
  343.      before this call)
  344.  
  345.   - NOTE that anyone wishing to define a new lock should coordinate
  346.     with me!!!
  347.  
  348.  
  349. void    cdecl clear_flag(int16 flag);
  350.  
  351.   - Clears a flag regardless of it's current status.  Returns nothing.
  352.  
  353.  
  354. CIB * cdecl CNgetinfo(int16 cn);
  355.  
  356.   - Returns a pointer to a CIB structure that has information
  357.     about the connection associated with the handle `cn'.
  358.   - This includes protocol, remote host, remote port, and
  359.     the local port.  The address of the local host can be
  360.     found with stik_cfg->client_ip
  361.   - The pointer is to a live part of the connection information,
  362.     so don't change anything unless you know what you're doing.
  363.   - The definition of a CIB can be found in the `trasnprt.h' file.
  364.